﻿@*
    For more information on enabling MVC for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860
*@
@{
    Layout = null;
}
<link href="~/lib/layui/css/layui.css" rel="stylesheet" />
<script src="~/lib/layui/layui.js"></script>
<script src="~/js/js.cookie.js"></script>
<script src="~/js/moment.js"></script>
<script src="~/lib/jquery/dist/jquery.js"></script>
<h3 style="text-align:center">登录页面</h3>

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>Demo</title>

    <!-- 请勿在项目正式环境中引用该 layui.css 地址 -->
 @*    <link href="//unpkg.com/layui@2.9.18/dist/css/layui.css" rel="stylesheet"> *@
</head>
<body>
    <style>
        .demo-login-container {
            width: 320px;
            margin: 21px auto 0;
        }

        .demo-login-other .layui-icon {
            position: relative;
            display: inline-block;
            margin: 0 2px;
            top: 2px;
            font-size: 26px;
        }
    </style>
    <form class="layui-form">
        <div class="demo-login-container">
            <div class="layui-form-item">
                <div class="layui-input-wrap">
                    <div class="layui-input-prefix">
                        <i class="layui-icon layui-icon-username"></i>
                    </div>
                    <input type="text" name="userName" value="" id="userName" lay-verify="required" placeholder="用户名" lay-reqtext="请填写用户名" autocomplete="off" class="layui-input" lay-affix="clear">
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-input-wrap">
                    <div class="layui-input-prefix">
                        <i class="layui-icon layui-icon-password"></i>
                    </div>
                    <input type="password" name="userPwd" value="" lay-verify="required" id="userPwd" placeholder="密   码" lay-reqtext="请填写密码" autocomplete="off" class="layui-input" lay-affix="eye">
                </div>
            </div>


            <div class="layui-form-item">
                <button type="button" class="layui-btn layui-btn-fluid" lay-submit lay-on="msg" onclick="GetLogin()">登录</button>
            </div>
            @* <div class="layui-form-item">
            <button class="layui-btn" lay-submit lay-filter="login">Login</button>
            </div> *@

        </div>
    </form>

    <!-- 请勿在项目正式环境中引用该 layui.js 地址 -->
 @*    <script src="//unpkg.com/layui@2.9.18/dist/layui.js"></script> *@
    <script>
        layui.use(function () {
            var form = layui.form;
            var layer = layui.layer;

        });
    </script>

</body>
</html>
@* <script src="https://cdnjs.cloudflare.com/ajax/libs/js - jwt/3.0.1/index.js"></script> *@
<script>
    layui.use(function () {
        var form = layui.form;
        var layer = layui.layer;

        //打开页面进行反填
        $("#userName").val(localStorage.getItem('userName'));
        $("#userPwd").val(localStorage.getItem('userPwd'));
    });

    function GetLogin() {
        var data = {
            userName: $("#userName").val(),
            userPwd: $("#userPwd").val(),
        }
        var a = '@ViewBag.RBACWrite';
        console.log(a)

        if (data.userName != "" && data.userPwd != "") {
            $.ajax({
                url: '@ViewBag.RBACWrite' + "/api/Users/Login",
                type: 'post',
                data: JSON.stringify(data),
                dataType: "json",
                async: true,
                contentType: "application/json",
                success: res => {
                    console.log(res)
                    if (res.code == 0) {
                        // console.log(res.data)
                        // return
                        layer.msg('登录成功');
                        //登录成功后 本地存储
                        localStorage.setItem('userName', res.data.userName);
                        localStorage.setItem('userPwd', res.data.userPwd);
                        location.href = "/Index/Index";
                    }
                    else {
                        layer.msg('保存失败');
                    }
                }

            })

        }



    }


</script>